package com.cskaoyan.controller.extendController;

import com.cskaoyan.model.bean.Coupon;
import com.cskaoyan.model.bo.extend.CouponBo;
import com.cskaoyan.model.bo.extend.ListUserBo;
import com.cskaoyan.model.vo.extend.BaseRespVo;
import com.cskaoyan.model.vo.extend.CouponUserVo;
import com.cskaoyan.model.vo.extend.CouponVo;
import com.cskaoyan.service.CouponService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author：Chunk
 * @Description:
 * @Date Created in 8:44 2021/4/9
 */
@RestController
@RequestMapping("admin/coupon")
public class CouponController {

    @Autowired
    CouponService couponService;

    @RequestMapping("list")
    @RequiresPermissions("admin:ad:list")
    public BaseRespVo couponList(CouponBo couponBo){
        CouponVo couponVo = couponService.queryCouponList(couponBo);
        return BaseRespVo.ok(couponVo);
    }

    @RequestMapping("listuser")
    @RequiresPermissions("admin:ad:listuser")
    public BaseRespVo listUser(ListUserBo listUserBo){

        CouponUserVo couponUserVo = couponService.queryListUser(listUserBo);
        return BaseRespVo.ok(couponUserVo);
    }

    @RequestMapping("create")
    @RequiresPermissions("admin:ad:create")
    public BaseRespVo create(@RequestBody Coupon coupon){
        Coupon couponVo = couponService.create(coupon);
        return BaseRespVo.ok(couponVo);
    }

    @RequestMapping("update")
    @RequiresPermissions("admin:ad:update")
    public BaseRespVo update(@RequestBody Coupon coupon){
        Coupon couponVo = couponService.update(coupon);
        return BaseRespVo.ok(couponVo);
    }

    @RequestMapping("delete")
    @RequiresPermissions("admin:ad:delete")
    public BaseRespVo delete(@RequestBody Coupon coupon){
        couponService.delete(coupon);
        return BaseRespVo.ok();
    }

    @RequestMapping("read")
    @RequiresPermissions("admin:ad:read")
    public BaseRespVo read(Integer id){
        Coupon coupon = couponService.queryById(id);
        return BaseRespVo.ok(coupon);
    }

}
